#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		string t = to_string(i);
		if (t.find("2") != -1 || t.find("0") != -1 || t.find("1") != -1 || t.find("9") != -1)
			ans += i;
	}
	cout << ans;
	return 0;
}
